package com.itheima.TCP.TCP发送协议;


import java.io.*;
import java.net.Socket;

public class ClientDemo3 {
    public static void main(String[] args) throws IOException {
        //创建Socket对象
        Socket socket = new Socket("127.0.0.1", 2);
        //读取本地文件
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("day629_网络编程入门\\abc.jpg"));
        //将本地文件写到服务器
        OutputStream os = socket.getOutputStream();
        //使用缓冲字节输出流进行封装
        BufferedOutputStream bos = new BufferedOutputStream(os);

        int b;
        while ((b = bis.read()) != -1) {
            bos.write(b);
            bos.flush();
        }

        //给服务器一个结束标记，告诉服务器文件已经传输完毕
        socket.shutdownOutput();

        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }

    }
}
